package logic

import (
	"context"
	"gorm.io/gorm"
	"property/mysql"

	"property/prorpc/internal/svc"
	"property/prorpc/prorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseListLogic) HouseList(in *prorpc.HouseListRequest) (*prorpc.HouseListResponse, error) {
	// todo: add your logic here and delete this line

	house := mysql.House{
		Model: gorm.Model{ID: uint(in.HouseId)},
	}
	mysql.DB.Debug().Find(&house)

	return &prorpc.HouseListResponse{
		Name:    house.Name,
		Address: house.Address,
		Price:   float32(house.Price),
	}, nil
}
